package com.ctshk.sapp.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.PushDTO;
import com.ctshk.rpc.cms.req.PushAddReq;
import com.ctshk.rpc.cms.req.PushQueryReq;
import com.ctshk.rpc.cms.req.PushUpdateReq;
import com.ctshk.rpc.cms.service.IPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 推送管理 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "推送管理",tags = "推送管理")
@RestController
@RequestMapping("/push")
public class PushController extends BaseController {

    @DubboReference
    private IPushService pushService;

    @ApiOperation(value = "新增推送", notes = "新增推送")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid PushAddReq req) {
        return pushService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询推送", notes = "查询推送")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{pushId}")
    public Result<PushDTO> queryById(@PathVariable("pushId") String pushId) {
        return pushService.queryById(pushId);
    }

    @ApiOperation(value = "推送分页查询", notes = "推送分页查询")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public Result<PageResponse<PushDTO>> queryList(@RequestBody @Valid PushQueryReq req) {
        return Result.success(pushService.queryList(req));
    }

    @ApiOperation(value = "修改推送", notes = "修改推送")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid PushUpdateReq req) {
        return pushService.update(req, getCurrentUser(getRequest()));
    }

}
